# -*- coding: utf-8 -*-
"""
Created on Sun Nov 19 13:44:13 2017

@author: Administrator
"""
import xlrd
import win32com.client 
import win32clipboard as w
import win32con,time
import chardet

voice= win32com.client.Dispatch("SAPI.SpVoice")
data=xlrd.open_workbook('形势与政策题库.xls')
table1=data.sheets()[0]
col1= table1.col_values(0)
col17= table1.col_values(7)
table2=data.sheets()[1]
col2= table2.col_values(0)
col27= table2.col_values(7)

table3=data.sheets()[2]
col3=table3.col_values(0)
col32= table3.col_values(2)
box1=[]
box17=[]
for i1 in col1:
    box1.append(i1.replace(' ',''))
for i17 in col17:
    box17.append(i17)

box2=[]
box27=[]
for i2 in col2:
    box2.append(i2.replace(' ',''))
for i27 in col27:
    box27.append(i27)

box3=[]
box32=[]
for i3 in col3:
    box3.append(i3.replace(' ',''))
for i32 in col32:
    box32.append(i32)
    
def getText():
        w.OpenClipboard()
        d = w.GetClipboardData(win32con.CF_TEXT)
        w.CloseClipboard()
        return d
box_question=[]
box_answer=[]
for item in box1:
    box_question.append(item)
for item in box2:
    box_question.append(item)
for item in box3:
    box_question.append(item)
for item in box17:
    box_answer.append(item)
for item in box27:
    box_answer.append(item)
for item in box32:
    box_answer.append(item)
def find():
    tex=getText().decode(chardet.detect(getText())['encoding'])
    text=tex.replace(' ','')   
    time.sleep(1)
    an=getText().decode(chardet.detect(getText())['encoding'])
    answer=an.replace(' ','')      
    if   text!= answer:                      
        n=-1
        for a in box_question:
            n+=1
            if answer.replace('\n','') in a:
                voice.Speak('选'+box_answer[n])
                break
        if n>len(box_question)-2:
            voice.Speak('题库中无此题目，请自行百度')
while 1:
    find()
    
